package com.njupt.sellsec.result;

/**
 * @Author: XJL
 * @Description:
 * @Date: Create in 14:44 2018/7/27
 * @Modified By:
 **/

public class Result<T> {

    private Integer code;
    private String msg;


    private T data;

    public String getMsg() {
        return msg;
    }

    public Integer getCode() {
        return code;
    }

    public T getData() {
        return data;
    }

    private Result(T data) {
        this.code = 0;
        this.msg="success";
        this.data = data;
    }

    private Result(CodeMsg codeMsg) {
        if (codeMsg==null){
            return;
        }else {

            this.code=codeMsg.getCode();
            this.msg = codeMsg.getMsg();
        }
    }

    private Result(String msg) {
        if (msg==null){
            return;
        }else {

            this.code=500;
            this.msg = msg;
        }
    }

    /**
     * success
     * @param data
     * @param <T>
     *
     * @return
     */
    public static <T> Result<T> success(T data){
        return new Result<T>(data);
    }

    public static <T> Result<T> error(CodeMsg codeMsg){
        return new Result<T>(codeMsg);
    }
    public static <T> Result<T> error(String msg){
        return new Result<T>(msg);
    }

}
